<!--
- Author:   .
- Date:    2018/2/5 0005.
- File:    fwh.
-->
<template>
  <div>
    <div class="">
      <div class="bgextension">
        <img src="../../assets/images/erweim4.png">
      </div>
    </div>
    <div class="Extension" v-show="deviceType == 'APICloud'"><a @click="saveToAlbum">保存到相册</a><a @click="wxShare">分享</a></div>
    <div class="pl20 pr20 mt35" style="position: fixed; bottom:  10px; width: 100%">
      <button type="button" class="but_1 wauto" @click="$utils.back">返回</button>
    </div>
  </div>
</template>

<script>
  import {mapModules, mapRules} from 'vuet'

  export default{
    mixins: [
      mapModules({memberInfo: 'memberInfo'}),
      mapRules({once: ['memberInfo']})
    ],
    data() {
      return {
        deviceType: this.$utils.getDeviceType()
      }
    },
    components: {},
    methods: {
      wxShare() {
        let _this = this
        let timestamp = _this.$utils.getTimestamp()
        window.api.download({
          url: _this.$config.website + '/wap/static/images/yshk-fwh.jpg',
          savePath: 'fs://yshk-fwh_' + timestamp + '.jpg',
          report: true,
          cache: true,
          allowResume: true
        }, function (ret, err) {
          if (ret.state == 1) {
            var wx = window.api.require('wx')
            wx.shareImage({
              apiKey: '',
              scene: 'session',
//          thumb: 'widget://a.jpg',
              contentUrl: 'fs://yshk-fwh_' + timestamp + '.jpg'
            }, function(ret, err) {
              if (ret.status) {
                _this.$toast('分享成功')
              } else {
                _this.$toast('分享失败:' + err.code)
              }
            })
          } else {
            _this.$toast('获取二维码失败', err.msg)
          }
        })
      },
      saveToAlbum() {
        let _this = this
        let timestamp = _this.$utils.getTimestamp()
        window.api.download({
          url: _this.$config.website + '/wap/static/images/yshk-fwh.jpg',
          savePath: 'fs://yshk-fwh_' + timestamp + '.jpg',
          report: true,
          cache: true,
          allowResume: true
        }, function (ret, err) {
          if (ret.state == 1) {
            window.api.saveMediaToAlbum({
              path: 'fs://yshk-fwh_' + timestamp + '.jpg'
            }, function (ret, err) {
              if (ret && ret.status) {
                _this.$toast('保存成功')
              } else {
                _this.$toast('保存失败:' + err.msg)
              }
            })
          } else {
            _this.$toast('下载二维码失败', err.msg)
          }
        })
      }
    }
  }
</script>

<style>

</style>